﻿using System;
using ExFlash.Records;

namespace ExFlash
{
    public class SwfHeader :ISwfSerializable
    {
        public static readonly int HeaderSize = 8;

        public Boolean IsCompressed
        {
            get;
            private set;
        }

        public Byte Version
        {
            get;
            private set;
        }

        public uint FileLength
        {
            get;
            private set;
        }

        public RectangleRecord FrameSize
        {
            get;
            private set;
        }

        public FixedFloat8Record FrameRate
        {
            get;
            private set;
        }

        public UInt16 FrameCount
        {
            get;
            private set;
        }

        public static Boolean CheckCompression(Byte[] arr, int offset)
        {
            return arr[offset] == 'C';
        }

        public static uint GetFileLength(Byte[] arr, int offset)
        {
            return BitConverter.ToUInt32(arr, offset);
        }

        #region ISwfSerializable Members

        public void SwfDeserialize(BinaryBitReader reader)
        {
            IsCompressed = reader.ReadByte() == 'C';
            reader.Position += 2;

            Version = reader.ReadByte();

            FileLength = reader.ReadUInt32();

            RectangleRecord rec = new RectangleRecord();
            rec.SwfDeserialize(reader);
            FrameSize = rec;

            FrameRate = new FixedFloat8Record();
            FrameRate.SwfDeserialize(reader);

            FrameCount = reader.ReadUInt16();
        }

        public void SwfSerialize(byte[] arr, ref int offset)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
